﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using Newtonsoft.Json.Linq;

namespace MTA.TripPlanner
{
    public class Stop : BaseFeed<Stop>
    {
        String _name = String.Empty;
        int _distance = 0;

        public string Name { get { return _name; } }
        public int Distance { get { return _distance; } }


        public static string FeedUrl
        {
            get { return ConfigurationManager.AppSettings["StopPage"]; }
        }

        public static Stop ConvertOne(JObject c)
        {
            return new Stop() { _id = int.Parse((string)c["id"]), 
                    _name = (String)c["text"], 
                    _distance = int.Parse((String)c["distance"]) };
        }


        public static List<Stop> GetByRouteId(int routeid)
        {
            JSONRequest request = new JSONRequest(FeedUrl);
            request.Params["route"] = routeid.ToString();

            return ConvertJSONArray(request, o => o["stops"]["item"], ConvertOne, true);
            
        }
    }
}
